import { Component, OnInit, ViewChild ,enableProdMode} from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { GoodsListComponent } from '../../components/goods-list/goods-list.component';
import { ApisService } from '../../apis.service';

@Component({
  selector: 'app-category',
  templateUrl: './category.component.html',
  styleUrls: ['./category.component.css']
})
export class CategoryComponent implements OnInit {
  //@ViewChild('goodsList')  goodsList: GoodsListComponent;
  catid:string="";
  currentPage:number=1;
  curPageNum:number=1;
  numPages:number=0;
  cid="";
  constructor(private router : Router,private route: ActivatedRoute,private apiService:ApisService) { 
    
  }
  pageChanged(ev){
    //this.currentPage=ev.page;
    this
      .router
      .navigate( ['category', this.cid],{queryParams:{pn:ev.page}});
  }
  ngOnInit() {
    this.route.params.subscribe(x=>{
      this.cid=x.id;
      this.apiService.category().then(cats=>{
        this.route.queryParams.subscribe(p=>{
          this.currentPage=p.pn||1;
          this.curPageNum= parseInt( p.pn);
          let item = cats.item_cats.find(o=>o.id==x.id);
          this.catid= item.cid;          
        });

      })
    });
  }

}
